package com.anzhen.interview.socket;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Date;

/**
 * Created by zhenan on 2017-7-10.
 */
public class Client {

    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("10.240.94.208", 7775);//创建一个客户端连接
        OutputStream out = socket.getOutputStream();//获取服务端的输出流，为了向服务端输出数据
        InputStream in=socket.getInputStream();//获取服务端的输入流，为了获取服务端输入的数据

        PrintWriter bufw=new PrintWriter(out,true);
        bufw.println("000002549<?xml version=\"1.0\" encoding=\"UTF-8\"?><BOSFXII xmlns=\"http://www.bankofshanghai.com/BOSFX/2010/05\"><TStFtStdAaaRq><CommonRqHdr><SPName>T24</SPName><RqUID>BOSC20170725191211789525</RqUID><NumTranCode></NumTranCode><ClearDate>20170725</ClearDate><TranDate>20170725</TranDate><TranTime>191211</TranTime><ChannelId>C31</ChannelId></CommonRqHdr><DebitMedType>I</DebitMedType><AcctNoDr>621090900999999990</AcctNoDr><CurrencyDr>CNY</CurrencyDr><CreditMedType>I</CreditMedType><AcctNoCr>621090900999999999</AcctNoCr><CurrencyCr>CNY</CurrencyCr><Amt>100</Amt><DCFlag>D</DCFlag><CommissionNo>0</CommissionNo><ChargeNo>1</ChargeNo><ChargeRec><ChargeType></ChargeType><ChargeAmt>1200.00</ChargeAmt></ChargeRec><FbNo>FBNO</FbNo><TxnType>TxnType</TxnType><TrnType></TrnType><OtherAcctNo>621090900999999990</OtherAcctNo><OtherCust>张三</OtherCust><OurAcctNo>621090900999999991</OurAcctNo><OurCust>李四</OurCust><OppBranchName>1</OppBranchName><ExchangeNo>1</ExchangeNo><VoucherType></VoucherType><VoucherNo></VoucherNo><IssueDt>20170725</IssueDt><PaymentPwd>123456</PaymentPwd><ClcRegion></ClcRegion><Pwd>123456</Pwd><AuthNo1>1</AuthNo1><AuthNo2>2</AuthNo2><AgentName>王五</AgentName><AgentNation>CHN</AgentNation><AgentType></AgentType><AgentId>500242199306259090</AgentId><Track2Info></Track2Info><Usage></Usage><Remark>备注</Remark><SeperateFlg>Y</SeperateFlg><VoucherFlag>Y</VoucherFlag><ReversalRef></ReversalRef><ReversalRem></ReversalRem><ProfitCentreDept></ProfitCentreDept><ProfitCentreCust></ProfitCentreCust><ChargeCode></ChargeCode><FrozenRefNo>1231</FrozenRefNo><TxnType_1></TxnType_1><SfSettleMetho></SfSettleMetho><CountryCode></CountryCode><TxnCode></TxnCode><ChlSerial></ChlSerial><RssCcy>Y</RssCcy><ChargesAcctNo></ChargesAcctNo><SfPmtDeclarN></SfPmtDeclarN><JwjnFlag></JwjnFlag><SfCusCif>cust111</SfCusCif><SfReceiptAmt>12.00</SfReceiptAmt><SfLcyAcc></SfLcyAcc><SfTxnCodeFx></SfTxnCodeFx><SfDealType></SfDealType><SfTxnCodeAc></SfTxnCodeAc><InterestVouFlg>Y</InterestVouFlg><SfBuyAmt>1.00</SfBuyAmt><SfCashAmt>1.00</SfCashAmt><SfFcyAcc></SfFcyAcc><OverdraftMedNo></OverdraftMedNo><BoughtRate></BoughtRate></TStFtStdAaaRq></BOSFXII>");//发送数据给服务端
        BufferedReader bufr=new BufferedReader(new InputStreamReader(in));
        while (true) {
            String line = bufr.readLine();//读取服务端传来的数据
            if (line == null) {
                break;
            }
            System.out.println("服务端说:"+line);//打印服务端传来的数据

        }
    }
}
